package com.jie.eduservice.controller;


import com.jie.commonutils.ResultEntity;
import com.jie.eduservice.entity.vo.SubjectVO;
import com.jie.eduservice.service.EduSubjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * <p>
 * 课程科目 前端控制器
 * </p>
 *
 * @author xzj
 * @since 2020-10-08
 */
//@CrossOrigin  // 解决跨域问题
@RestController
@RequestMapping("/eduservice/subject")
public class EduSubjectController {

    private final EduSubjectService subjectService;

    @Autowired
    public EduSubjectController(EduSubjectService subjectService) {
        this.subjectService = subjectService;
    }

    // 课程分类列表(树形)
    @GetMapping("/getAllSubjects")
    public ResultEntity getAllSubjects() {
        List<SubjectVO> list = subjectService.getAllSubjects();
        return ResultEntity.ok().data("list", list);
    }

    // 添加课程分类
    // 获取上传过来的文件, 把文件内容读取出来
    @PostMapping("/addSubject")
    public ResultEntity addSubject(
            // 获取到上传的excel文件
            MultipartFile file
    ) {
        subjectService.saveSubject(file);
        return ResultEntity.ok();
    }

}

